/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.sql.ResultSet;
import java.sql.SQLException;
import model.City;
import model.Route;

/**
 *
 * @author hans
 */
public class RouteHandler {

    private DatabaseConnection db;

    public RouteHandler(DatabaseConnection db) {
        this.db = db;
    }

    public Route getRoute(City start, City dest) throws SQLException {
        Route r = null;
        String sql = "Select * from route where origin = " + start.getId() + " and destination = " + dest.getId();
        ResultSet rs = db.selectQuery(sql);
        if (rs.next()) {
            r = new Route(start, dest, rs.getInt("distance"));
        }
        return r;
    }
}
